module.exports = {
  meta: {
    type: "problem",
    docs: {
      description: "禁止 window.xxx = ... 这样的全局变量泄露",
    },
    schema: [],
    messages: {
      possibleLeak:
        "Avoid attaching properties like '{{name}}' to window globally, which may cause memory leaks.",
    },
  },

  create(context) {
    return {
      AssignmentExpression(node) {
        const { left, operator } = node;

        // 检查 window.leakList = []
        if (
          operator === "=" &&
          left.type === "MemberExpression" &&
          left.object.type === "Identifier" &&
          left.object.name === "window"
        ) {
          context.report({
            node,
            message: `避免将 ${left.property.name} 的属性挂载到 window 上，这可能导致内存泄露。`,
          });
        }
      },
    };
  },
};
